using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;

public class GroundMove : MonoBehaviour
{
    public float maxDistance;
    public float frequency;
    public float diretion;
    float time;

    public bool canMove;

    Vector3 orginalLoc;
    Vector3 deltaLoc;
    float deltaPos;

    // Start is called before the first frame update
    void Awake()
    {
        orginalLoc = transform.position;
    }

    // Update is called once per frame
    void Update()
    {
        if (canMove)
        {
            Move();
        }
    }

    private void Move()
    {
        deltaPos = maxDistance * math.sin(frequency * time);
        deltaLoc = new Vector3(math.cos(diretion)*deltaPos, math.sin(diretion) * deltaPos, 0);
        transform.position = orginalLoc +deltaLoc;

        time += Time.deltaTime;
        if(frequency * time >= 2 * math.PI)
        {
            time -= 2 * math.PI;
        }
    }
}
